<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>首页</title>
</head>
<script type="text/javascript" src="static/js/jquery-3.2.1.js">
	
</script>
<script type="text/javascript">
	//确认登录信息，允许登陆的变量
	var res = false;
	//根据返回值确认用户名状态
	function ine(data) {
		if (data == 1) {
			document.getElementById("checkUN").innerHTML = "<b style='color: red'></b>";
			res = true;
		} else if (data == 2) {
			document.getElementById("checkUN").innerHTML = "<b style='color:red'>用户名不能为空</b>";
			res = false;
		} else if (data == 3) {
			document.getElementById("checkUN").innerHTML = "<b style='color:red'>用户名不存在</b>"
			res = false;
		} else if (data == 0) {
			document.getElementById("checkUN").innerHTML = "<b style='color:red'>ajax成功返回值为空</b>"
			res = false;
		} else {
			document.getElementById("checkUN").innerHTML = "<b style='color:red'>未知错误</b>"
			res = false;
		}
	}
	//确认用户名
	function checkUser() {
		var uname = $("#username").val();
		var s = 0;
		$.ajax({
			type : "post",
			url : 'checkUser',
			data : "uname=" + uname,
			success : function(data) {
				ine(data);
			}
		});
	}
	//根据返回数据确认密码状态
	function upw(data) {
		if (data == 1) {
			document.getElementById("checkUP").innerHTML = "<b style='color: red'>密码错误</b>";
			res = false;
		} else if (data == 2) {
			document.getElementById("checkUP").innerHTML = "<b style='color:red'>密码不能为空</b>";
			res = false;
		} else if (data == 3) {
			res = true;
		} else {
			document.getElementById("checkUP").innerHTML = "<b style='color:red'>未知错误</b>";
			res = false;
		}
	}
	//确认密码
	function checkUpwd() {
		var upwd = $("#password").val();
		var uname = $("#username").val();
		$.ajax({
			type : "post",
			url : 'checkupwd',
			data : {
				"uname" : uname,
				"upwd" : upwd
			},
			success : function(data) {
				upw(data);
			}
		});
	}
	//确认信息后返回true，允许登陆
	function cheSub() {
		return res;
	}
	/* $(document).ready(function() {
		$("#uname").blur(function() {
			checkUser();
		});
	}) */
</script>
<body  onload="Javascript:document.index.uname.focus()">
	<h1 align="center">
		<span style="color: blue;">用户登录</span>
	</h1>
	<form name="index" action="login" method="post" onsubmit="return cheSub()">
		<table align="center">
			<tr>
				<td>用户名:</td>
				<td><input id="username" type="text" name="uname"
					onblur="checkUser()" onfocus=true/><span id="checkUN"></span></td>
			</tr>
			<tr>
				<td>密&nbsp;&nbsp;&nbsp;码:</td>
				<td><input id="password" type="password" name="upwd"
					onblur="checkUpwd()" /><span id="checkUP"></span></td>
			</tr>
			<tr>
				<td colspan="2">
					<button onclick="">返回首页</button>
					<button>找回密码</button> <input type="submit" value="登录" />
					<button>
						<!-- 跳转到注册页面 -->
						<a href="skipzhuce">新用户注册</a>
					</button> <a href="#">收藏本站</a>
				</td>
			</tr>
		</table>
	</form>
</body>
</html>